// -----------------------------------------------------------
// Game Framework
// Copyright © 2024-2024 deadcycle. All rights reserved.
// Homepage: https://deadcycle.gitee.io
// Feedback: deadcycle@163.com
// -----------------------------------------------------------

#if ODIN_INSPECTOR

using System;
using System.Collections.Generic;
using System.Reflection;

using GameApp.Editor;

using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;

namespace UIWidget.Editor
{
    public class MirrorMeshEffectInspector { }

    public class MirrorMeshEffectAttrProcessor : OdinAttributeProcessor<MirrorMeshEffect>
    {
        private readonly Dictionary<string, Action<List<Attribute>>> m_FieldProcessorDict;
        private readonly Dictionary<string, Action<List<Attribute>>> m_MethodProcessorDict;

        public MirrorMeshEffectAttrProcessor()
        {
            m_FieldProcessorDict = new Dictionary<string, Action<List<Attribute>>>
            {
                { "m_MirrorType", FieldMirrorType }, { "m_FlipMirror", FieldFlipMirror },
            };

            m_MethodProcessorDict = new Dictionary<string, Action<List<Attribute>>>
            {
                { "SetNativeSize", MethodSetNativeSize },
            };

            EnumNiceNameHelper.RegisterEnumNiceName<MirrorMeshEffect.MirrorType>();
        }

        public override void ProcessChildMemberAttributes(InspectorProperty parentProperty,
            MemberInfo member,
            List<Attribute> attributes)
        {
            if (member.MemberType == MemberTypes.Field &&
                m_FieldProcessorDict.TryGetValue(member.Name,
                    out Action<List<Attribute>> fieldProcessor))
            {
                fieldProcessor.Invoke(attributes);
            }
            else if (member.MemberType == MemberTypes.Method &&
                m_MethodProcessorDict.TryGetValue(member.Name,
                    out Action<List<Attribute>> methodProcessor))
            {
                methodProcessor.Invoke(attributes);
            }
        }

        private void FieldMirrorType(List<Attribute> attributes)
        {
            attributes.Add(new LabelTextAttribute("镜像复制方式"));

            attributes.Add(new InfoBoxAttribute("Image开启`use sprite mesh`选项, 镜像复制效果无效.",
                InfoMessageType.Error, "EffectInvalid"));
        }

        private void FieldFlipMirror(List<Attribute> attributes)
        {
            attributes.Add(new LabelTextAttribute("翻转复制的镜像图形"));

            attributes.Add(new InfoBoxAttribute("1/4镜像此选项无效, 水平镜像对应垂直翻转, 垂直镜像对应水平翻转."));
        }

        private void MethodSetNativeSize(List<Attribute> attributes)
        {
            attributes.Add(new ButtonAttribute("Set Native Size"));
            attributes.Add(new EnableIfAttribute("CanNativeSize"));
        }
    }
}

#endif